
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_CN">
  <head>
    <meta charset="utf-8" />
    <title>内置常量 &#8212; Python 3.7.8 文档</title>
    <link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/language_data.js"></script>
    <script type="text/javascript" src="../_static/translations.js"></script>
    
    <script type="text/javascript" src="../_static/sidebar.js"></script>
    
    <link rel="search" type="application/opensearchdescription+xml"
          title="在 Python 3.7.8 文档 中搜索"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="关于这些文档" href="../about.html" />
    <link rel="index" title="索引" href="../genindex.html" />
    <link rel="search" title="搜索" href="../search.html" />
    <link rel="copyright" title="版权所有" href="../copyright.html" />
    <link rel="next" title="内置类型" href="stdtypes.html" />
    <link rel="prev" title="内置函数" href="functions.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
    <link rel="canonical" href="https://docs.python.org/3/library/constants.html" />
    
    <script type="text/javascript" src="../_static/copybutton.js"></script>
    
    
    
    
    <style>
      @media only screen {
        table.full-width-table {
            width: 100%;
        }
      }
    </style>
 

  </head><body>
  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>导航</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="总目录"
             accesskey="I">索引</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python 模块索引"
             >模块</a> |</li>
        <li class="right" >
          <a href="stdtypes.html" title="内置类型"
             accesskey="N">下一页</a> |</li>
        <li class="right" >
          <a href="functions.html" title="内置函数"
             accesskey="P">上一页</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &#187;</li>
        <li>
          <a href="../index.html">3.7.8 Documentation</a> &#187;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Python 标准库</a> &#187;</li>
    <li class="right">
        

    <div class="inline-search" style="display: none" role="search">
        <form class="inline-search" action="../search.html" method="get">
          <input placeholder="快速搜索" type="text" name="q" />
          <input type="submit" value="转向" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </form>
    </div>
    <script type="text/javascript">$('.inline-search').show(0);</script>
         |
    </li>

      </ul>
    </div>    

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="built-in-constants">
<span id="built-in-consts"></span><h1>内置常量<a class="headerlink" href="#built-in-constants" title="永久链接至标题">¶</a></h1>
<p>有少数的常量存在于内置命名空间中。 它们是：</p>
<dl class="data">
<dt id="False">
<code class="sig-name descname">False</code><a class="headerlink" href="#False" title="永久链接至目标">¶</a></dt>
<dd><p><a class="reference internal" href="functions.html#bool" title="bool"><code class="xref py py-class docutils literal notranslate"><span class="pre">bool</span></code></a> 类型的假值。 给 <code class="docutils literal notranslate"><span class="pre">False</span></code> 赋值是非法的并会引发 <a class="reference internal" href="exceptions.html#SyntaxError" title="SyntaxError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxError</span></code></a>。</p>
</dd></dl>

<dl class="data">
<dt id="True">
<code class="sig-name descname">True</code><a class="headerlink" href="#True" title="永久链接至目标">¶</a></dt>
<dd><p><a class="reference internal" href="functions.html#bool" title="bool"><code class="xref py py-class docutils literal notranslate"><span class="pre">bool</span></code></a> 类型的真值。 给 <code class="docutils literal notranslate"><span class="pre">True</span></code> 赋值是非法的并会引发 <a class="reference internal" href="exceptions.html#SyntaxError" title="SyntaxError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxError</span></code></a>。</p>
</dd></dl>

<dl class="data">
<dt id="None">
<code class="sig-name descname">None</code><a class="headerlink" href="#None" title="永久链接至目标">¶</a></dt>
<dd><p><code class="docutils literal notranslate"><span class="pre">NoneType</span></code> 类型的唯一值。 <code class="docutils literal notranslate"><span class="pre">None</span></code> 经常用于表示缺少值，当因为默认参数未传递给函数时。 给 <code class="docutils literal notranslate"><span class="pre">None</span></code> 赋值是非法的并会引发 <a class="reference internal" href="exceptions.html#SyntaxError" title="SyntaxError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxError</span></code></a>。</p>
</dd></dl>

<dl class="data">
<dt id="NotImplemented">
<code class="sig-name descname">NotImplemented</code><a class="headerlink" href="#NotImplemented" title="永久链接至目标">¶</a></dt>
<dd><p>二进制特殊方法应返回的特殊值（例如，<a class="reference internal" href="../reference/datamodel.html#object.__eq__" title="object.__eq__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__eq__()</span></code></a>、<a class="reference internal" href="../reference/datamodel.html#object.__lt__" title="object.__lt__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__lt__()</span></code></a>、<code class="xref py py-meth docutils literal notranslate"><span class="pre">__add</span> <span class="pre">__()</span></code>、<a class="reference internal" href="../reference/datamodel.html#object.__rsub__" title="object.__rsub__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__rsub__()</span></code></a> 等）表示操作没有针对其他类型实现；为了相同的目的，可以通过就地二进制特殊方法（例如，<code class="xref py py-meth docutils literal notranslate"><span class="pre">__imul</span> <span class="pre">__()</span></code>、<code class="xref py py-meth docutils literal notranslate"><span class="pre">__</span> <span class="pre">rightnd__()</span></code> 等）返回。 它的逻辑值为真。</p>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>当二进制（或就地）方法返回``NotImplemented``时，解释器将尝试对另一种类型（或其他一些回滚操作，取决于运算符）的反射操作。 如果所有尝试都返回``NotImplemented``，则解释器将引发适当的异常。 错误返回的``NotImplemented``将导致误导性错误消息或返回到Python代码中的``NotImplemented``值。</p>
<p>参见 <a class="reference internal" href="numbers.html#implementing-the-arithmetic-operations"><span class="std std-ref">实现算数运算</span></a> 为例。</p>
</div>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p><code class="docutils literal notranslate"><span class="pre">NotImplementedError</span></code> 和 <code class="docutils literal notranslate"><span class="pre">NotImplemented</span></code> 不可互换，即使它们有相似的名称和用途。 有关何时使用它的详细信息，请参阅 <a class="reference internal" href="exceptions.html#NotImplementedError" title="NotImplementedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NotImplementedError</span></code></a>。</p>
</div>
</dd></dl>

<span class="target" id="index-0"></span><dl class="data">
<dt id="Ellipsis">
<code class="sig-name descname">Ellipsis</code><a class="headerlink" href="#Ellipsis" title="永久链接至目标">¶</a></dt>
<dd><p>与省略号文字字面 “<code class="docutils literal notranslate"><span class="pre">...</span></code>” 相同。 特殊值主要与用户定义的容器数据类型的扩展切片语法结合使用。</p>
</dd></dl>

<dl class="data">
<dt id="__debug__">
<code class="sig-name descname">__debug__</code><a class="headerlink" href="#__debug__" title="永久链接至目标">¶</a></dt>
<dd><p>如果 Python 没有以 <a class="reference internal" href="../using/cmdline.html#cmdoption-o"><code class="xref std std-option docutils literal notranslate"><span class="pre">-O</span></code></a> 选项启动，则此常量为真值。 另请参见 <a class="reference internal" href="../reference/simple_stmts.html#assert"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">assert</span></code></a> 语句。</p>
</dd></dl>

<div class="admonition note">
<p class="admonition-title">注解</p>
<p>变量名 <a class="reference internal" href="#None" title="None"><code class="xref py py-data docutils literal notranslate"><span class="pre">None</span></code></a>，<a class="reference internal" href="#False" title="False"><code class="xref py py-data docutils literal notranslate"><span class="pre">False</span></code></a>，<a class="reference internal" href="#True" title="True"><code class="xref py py-data docutils literal notranslate"><span class="pre">True</span></code></a> 和 <code class="xref py py-data docutils literal notranslate"><span class="pre">__</span> <span class="pre">debug__</span></code> 无法重新赋值（赋值给它们，即使是属性名，将引发 <a class="reference internal" href="exceptions.html#SyntaxError" title="SyntaxError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxError</span></code></a> ），所以它们可以被认为是“真正的”常数。</p>
</div>
<div class="section" id="constants-added-by-the-site-module">
<h2>由 <a class="reference internal" href="site.html#module-site" title="site: Module responsible for site-specific configuration."><code class="xref py py-mod docutils literal notranslate"><span class="pre">site</span></code></a> 模块添加的常量<a class="headerlink" href="#constants-added-by-the-site-module" title="永久链接至标题">¶</a></h2>
<p><a class="reference internal" href="site.html#module-site" title="site: Module responsible for site-specific configuration."><code class="xref py py-mod docutils literal notranslate"><span class="pre">site</span></code></a> 模块（在启动期间自动导入，除非给出 <a class="reference internal" href="../using/cmdline.html#id3"><code class="xref std std-option docutils literal notranslate"><span class="pre">-S</span></code></a> 命令行选项）将几个常量添加到内置命名空间。 它们对交互式解释器 shell 很有用，并且不应在程序中使用。</p>
<dl class="data">
<dt id="quit">
<code class="sig-name descname">quit</code><span class="sig-paren">(</span><em class="sig-param">code=None</em><span class="sig-paren">)</span><a class="headerlink" href="#quit" title="永久链接至目标">¶</a></dt>
<dt id="exit">
<code class="sig-name descname">exit</code><span class="sig-paren">(</span><em class="sig-param">code=None</em><span class="sig-paren">)</span><a class="headerlink" href="#exit" title="永久链接至目标">¶</a></dt>
<dd><p>当打印此对象时，会打印出一条消息，例如“Use quit() or Ctrl-D (i.e. EOF) to exit”，当调用此对象时，将使用指定的退出代码来引发 <a class="reference internal" href="exceptions.html#SystemExit" title="SystemExit"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SystemExit</span></code></a>。</p>
</dd></dl>

<dl class="data">
<dt id="copyright">
<code class="sig-name descname">copyright</code><a class="headerlink" href="#copyright" title="永久链接至目标">¶</a></dt>
<dt id="credits">
<code class="sig-name descname">credits</code><a class="headerlink" href="#credits" title="永久链接至目标">¶</a></dt>
<dd><p>打印或调用的对象分别打印版权或作者的文本。</p>
</dd></dl>

<dl class="data">
<dt id="license">
<code class="sig-name descname">license</code><a class="headerlink" href="#license" title="永久链接至目标">¶</a></dt>
<dd><p>当打印此对象时，会打印出一条消息“Type license() to see the full license text”，当调用此对象时，将以分页形式显示完整的许可证文本（每次显示一屏）。</p>
</dd></dl>

</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../contents.html">目录</a></h3>
  <ul>
<li><a class="reference internal" href="#">内置常量</a><ul>
<li><a class="reference internal" href="#constants-added-by-the-site-module">由 <code class="xref py py-mod docutils literal notranslate"><span class="pre">site</span></code> 模块添加的常量</a></li>
</ul>
</li>
</ul>

  <h4>上一个主题</h4>
  <p class="topless"><a href="functions.html"
                        title="上一章">内置函数</a></p>
  <h4>下一个主题</h4>
  <p class="topless"><a href="stdtypes.html"
                        title="下一章">内置类型</a></p>
  <div role="note" aria-label="source link">
    <h3>本页</h3>
    <ul class="this-page-menu">
      <li><a href="../bugs.html">提交 Bug</a></li>
      <li>
        <a href="https://github.com/python/cpython/blob/3.7/Doc/library/constants.rst"
            rel="nofollow">显示源代码
        </a>
      </li>
    </ul>
  </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>导航</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="总目录"
             >索引</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python 模块索引"
             >模块</a> |</li>
        <li class="right" >
          <a href="stdtypes.html" title="内置类型"
             >下一页</a> |</li>
        <li class="right" >
          <a href="functions.html" title="内置函数"
             >上一页</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &#187;</li>
        <li>
          <a href="../index.html">3.7.8 Documentation</a> &#187;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" >Python 标准库</a> &#187;</li>
    <li class="right">
        

    <div class="inline-search" style="display: none" role="search">
        <form class="inline-search" action="../search.html" method="get">
          <input placeholder="快速搜索" type="text" name="q" />
          <input type="submit" value="转向" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </form>
    </div>
    <script type="text/javascript">$('.inline-search').show(0);</script>
         |
    </li>

      </ul>
    </div>  
    <div class="footer">
    &copy; <a href="../copyright.html">版权所有</a> 2001-2020, Python Software Foundation.
    <br />
    Python 软件基金会是一个非盈利组织。
    <a href="https://www.python.org/psf/donations/">请捐助。</a>
    <br />
    最后更新于 6月 29, 2020.
    <a href="../bugs.html">发现了问题</a>？
    <br />
    使用<a href="http://sphinx.pocoo.org/">Sphinx</a>2.3.1 创建。
    </div>

  </body>
</html>